package belf.migrate.engine.job.verify.utils;

import java.util.List;
import java.util.Locale;

public enum KingbaseConventType {

    VARCHAR(List.of("character varying"), "varchar"),

    SET(List.of("character"),"set"),

    SMALLINT(List.of("integer", "smallint"), "smallint"),

    TINYINT(List.of("smallint", "bit", "tinyint"), "tinyint"),

    MEDIUMINT(List.of("integer"), "mediumint"),

    INT(List.of("integer"), "int"),

    CHAR(List.of("character"), "char"),

    ENUM(List.of("character"), "enum"),

    DECIMAL(List.of("numeric"), "decimal");

    private List<String> conventType;

    private String mappingType;

    KingbaseConventType(List<String> conventType, String mappingType) {
        this.mappingType = mappingType;
        this.conventType = conventType;
    }

    public String getMappingType() {
        return mappingType;
    }

    public void setMappingType(String mappingType) {
        this.mappingType = mappingType;
    }

    public List<String> getConventType() {
        return conventType;
    }

    public void setConventType(List<String> conventType) {
        this.conventType = conventType;
    }

    public static boolean equals(String convertType, String mappingType) {
        for (KingbaseConventType kingbaseConventType : KingbaseConventType.values()) {
            if (kingbaseConventType.getConventType().contains(convertType.toLowerCase(Locale.ROOT)) && kingbaseConventType.getMappingType().equalsIgnoreCase(mappingType)) {
                return true;
            }
        }
        return false;
    }

    public static boolean contains(String mappingType) {
        for (KingbaseConventType kingbaseConventType : KingbaseConventType.values()) {
            if (kingbaseConventType.getMappingType().equalsIgnoreCase(mappingType)) {
                return true;
            }
        }
        return false;
    }
}
